<template>
  <div class="data-container">
    <div class="tab-list">
      <div class="item" @click="handleTab(0)">AI一组线索转化</div>
      <div class="item active">AI二组线索转化</div>
    </div>
    <div class="tab-list tab-list2">
      <div class="item" :class="{ active: active === 1 }" @click="handleTab(1)">全部</div>
      <div class="item" :class="{ active: active === 2 }" @click="handleTab(2)">昨天</div>
      <div class="item" :class="{ active: active === 3 }" @click="handleTab(3)">今天</div>
      <div class="item" :class="{ active: active === 4 }" @click="handleTab(4)">本周</div>
      <div class="item" :class="{ active: active === 5 }" @click="handleTab(5)">本月</div>
      <div class="item" :class="{ active: active === 6 }" @click="handleTab(6)">今年</div>
    </div>
    <dv-decoration-2 style="width: 360px; height: 5px" :dur="30" />

    <div class="tab-panel" v-if="dataList">
      <div class="funnel-list">
        <div class="item" :class="{ animation: animation }">
          <div class="text">
            <div class="name">AI推送数据</div>
            <div class="value">{{ dataList.ai_total }}</div>
          </div>
        </div>
        <div class="item" :class="{ animation: animation }">
          <div class="text">
            <div class="name">电话回访</div>
            <div class="value">{{ dataList.phone_follow_total }}</div>
          </div>
          <div class="percent">{{ percent(dataList.phone_follow_total, dataList.ai_total) }}%</div>
        </div>
        <div class="item" :class="{ animation: animation }">
          <div class="text">
            <div class="name">有效数据</div>
            <div class="value">{{ dataList.effect_total }}</div>
          </div>
          <div class="percent">{{ percent(dataList.effect_total, dataList.phone_follow_total) }}%</div>
        </div>
      </div>
      <div class="data-list">
        <div class="item">
          <div class="value">{{ dataList.self_total }}</div>
          <div class="name">独享</div>
        </div>
        <div class="item">
          <div class="value">{{ dataList.pub_total }}</div>
          <div class="name">发布资产</div>
        </div>
        <div class="item">
          <div class="value">{{ dataList.no_talk_total }}</div>
          <div class="name">未接通</div>
        </div>
      </div>
      <!-- 排名 -->
      <div class="rank-box">
        <div class="title">员工排名</div>
        <div class="rank-list">
          <div class="item">
            <div class="name">{{ (dataList.user_order && dataList.user_order[1] && dataList.user_order[1].follow_man) || '--' }}</div>
            <div class="podium" :class="{ animation: animation }">
              <p class="text1">NO.2</p>
              <p class="text2">{{ (dataList.user_order && dataList.user_order[1] && dataList.user_order[1].total) || '--' }}条</p>
            </div>
          </div>
          <div class="item">
            <div class="name">{{ (dataList.user_order && dataList.user_order[0] && dataList.user_order[0].follow_man) || '--' }}</div>
            <div class="podium" :class="{ animation: animation }">
              <p class="text1">NO.1</p>
              <p class="text2">{{ (dataList.user_order && dataList.user_order[0] && dataList.user_order[0].total) || '--' }}条</p>
            </div>
          </div>
          <div class="item">
            <div class="name">{{ (dataList.user_order && dataList.user_order[2] && dataList.user_order[2].follow_man) || '--' }}</div>
            <div class="podium" :class="{ animation: animation }">
              <p class="text1">NO.3</p>
              <p class="text2">{{ (dataList.user_order && dataList.user_order[2] && dataList.user_order[2].total) || '--' }}条</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getIndexRightData } from '@/api/realTime/index'

export default {
  name: 'panel1',
  data() {
    return {
      active: 1,
      dataList: [],
      timer: null,
      animation: false,
    }
  },
  computed: {},
  mounted() {
    this.getData()
  },
  methods: {
    onInterval() {
      this.handleTab((this.active % 6) + 1, 'interval')
    },
    // 获取数据
    getData() {
      const info = {
        clue_type: this.active,
      }
      const formData = new FormData()
      for (let key in info) {
        formData.set(key, info[key])
      }
      getIndexRightData(formData)
        .then((res) => {
          const { update_time, data } = res.data
          this.$emit('update_time', update_time)
          this.dataList = data
          setTimeout(() => {
            this.animation = true
          }, 200)
        })
        .catch(() => {
          this.$emit('stopInterval')
        })
    },
    // tab切换
    handleTab(index, type) {
      if (type !== 'interval') {
        this.$emit('pauseInterval')
      }
      if (index === 0) {
        this.$toast('暂未开通')
        return
      }
      this.active = index
      this.animation = false
      this.getData()
    },
    // 百分数
    percent(a, b) {
      if (a === 0 || b === 0) {
        return 0
      } else {
        return parseInt((a / b) * 100)
      }
    },
  },
}
</script>
<style lang="scss" scoped>
$bgColor: #060a22;
$mainColor: #68cee0;
$mainColorOpcity: rgba(104, 206, 224, 0.3);
.data-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding: 20px;
  overflow: hidden;
}
.tab-list {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  &.tab-list2 {
    margin-top: 4px;
    .item {
      width: 60px;
    }
  }
  .item {
    width: 100px;
    height: 30px;
    border: 1px solid #ffffff;
    border-right: none;
    color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    &:hover {
      border-color: $mainColor;
      color: $mainColor;
    }
    &.active {
      border-color: $mainColor;
      background: $mainColorOpcity;
      font-weight: bold;
      color: $mainColor;
    }

    &:last-child {
      margin-right: 0;
      border-radius: 0 3px 3px 0;
      border: 1px solid #ffffff;
    }
    &:first-child {
      border-radius: 3px 0 0 3px;
    }
  }
}

.tab-panel {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  .funnel-list {
    width: 100%;
    height: 50%;
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .item {
      width: 100%;
      position: relative;
      height: 8vh;
      margin-bottom: 4px;
      .text {
        text-align: center;
        position: absolute;
        padding-top: 2vh;
        color: transparent;
        .name {
          margin-bottom: 6px;
        }
      }
      .percent {
        position: relative;
        color: $mainColor;
        width: 100%;
        text-align: right;
        padding-right: 10px;
        top: -8px;
        &::before {
          content: '';
          position: absolute;
          right: 50px;
          top: 5px;
          width: 40%;
          height: 1px;
          background: $mainColor;
        }
      }

      &.animation {
        .text {
          color: #ffffff;
          transition: 2s;
        }
        &::before {
          transition: 0.5s;
          border: 8vh solid transparent;
          border-left-width: 15px;
          border-right-width: 15px;
          border-top-color: #68cee0;
        }
      }
      &::before {
        content: '';
        position: absolute;
        height: 0;
        border: 0vh solid transparent;
        border-left-width: 15px;
        border-right-width: 15px;
        border-top-color: #68cee0;
      }
      &:nth-child(1) {
        .text {
          width: 50%;
        }
        &::before {
          width: 50%;
          left: 0;
        }
      }
      &:nth-child(2) {
        .text {
          width: calc(50% - 30px);
          left: 15px;
        }
        &::before {
          width: calc(50% - 30px);
          left: 15px;
          border-top-color: rgba(104, 206, 224, 0.7);
        }
      }
      &:nth-child(3) {
        .text {
          width: calc(50% - 60px);
          left: 30px;
        }
        &::before {
          width: calc(50% - 60px);
          left: 30px;
          border-top-color: rgba(104, 206, 224, 0.4);
        }
        .percent {
          padding-right: 25px;
          &::before {
            right: 65px;
          }
        }
      }
    }
  }
  .data-list {
    width: 100%;
    height: 10%;
    margin-top: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    .item {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      border: 1px solid $mainColor;
      border-radius: 3px;
      width: 30%;
      height: 50px;
      margin-right: 10px;
      &:last-child {
        margin-right: 0;
      }
      .name {
        font-size: 14px;
        margin-top: 4px;
      }
      .value {
        font-size: 16px;
        color: #ffffff;
        font-weight: bold;
      }
    }
  }
  .rank-box {
    width: 100%;
    height: 40%;
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .title {
      font-size: 16px;
      font-weight: bold;
    }
    .rank-list {
      width: 100%;
      height: 70%;
      margin-top: 10px;
      display: flex;
      justify-content: center;
      align-items: flex-end;
      .item {
        width: 30%;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        align-items: center;
        margin-right: 4px;
        .name {
          color: #ffffff;
          font-weight: bold;
        }
        .podium {
          margin-top: 10px;
          width: 100%;
          height: 0%;
          &.animation {
            transition: 0.5s;
            height: 90%;
          }
          background: rgba(104, 206, 224, 1);
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          color: #ffffff;
          .text1 {
            font-size: 16px;
            margin: 0;
            margin-bottom: 10px;
          }
          .text2 {
            margin: 0;
          }
        }
        &:first-child {
          .podium {
            background: rgba(104, 206, 224, 0.6);
            &.animation {
              transition: 1s;
              height: 70%;
            }
          }
        }
        &:last-child {
          margin-right: 0;
          .podium {
            background: rgba(104, 206, 224, 0.2);
            &.animation {
              transition: 1s;
              height: 50%;
            }
          }
        }
      }
    }
  }
}
</style>
